package com.bos.web.action;

import com.bos.domian.system.Menu;
import com.bos.domian.system.User;
import com.bos.service.MenuService;
import com.bos.web.BaseAction;
import com.opensymphony.xwork2.ActionContext;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.apache.struts2.convention.annotation.*;
import org.omg.PortableInterceptor.SUCCESSFUL;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * @author misterWei
 * @create 2019年01月01号:20点34分
 * @mailbox mynameisweiyan@gmail.com
 */
@ParentPackage("json-default")
@Actions
@Namespace("/")
@Controller
public class MenuAction extends BaseAction<Menu> {
    @Autowired
    private MenuService menuService;

    @Action(value = "menu_list", results = {@Result(name = "success", type = "json")})
    public String findMenuList() {
        List<Menu> menuList = menuService.findMenuAll();
        ActionContext.getContext().getValueStack().push(menuList);
        return SUCCESS;
    }

    @Action(value = "menu_add",results = {@Result(name="success",type = "redirect",location = "pages/system/menu.html")})
    public String menuAdd(){
        menuService.add(model);

        return SUCCESS;
    }
    /**
     * 根据不同角色显示菜单列表
     */
    @Action(value = "show_menu",results = {@Result(type = "json",name = "success")})
    public String showMenu(){
  //获取到当前用户
        Subject subject = SecurityUtils.getSubject();
        User user = (User) subject.getPrincipal();
        List<Menu> menuList = menuService.findByUser(user);
        ActionContext.getContext().getValueStack().push(menuList);
        return SUCCESS;
    }
}
